<!DOCTYPE html>
<html>
<head>
    <title>WebSocket</title>
    <meta http-equiv="Content-Type" content="text/html;charset=utf-8"></head>
<body>
    <script type="text/javascript">
        var sock = null;
        var wsuri = "ws://127.0.0.1:9090/";
        <!-- 在这个网站上可以对websocket进行测试 www.websocket.org/echo.html -->
        var wsUri = "ws://echo.websocket.org/";

        window.onload = function() {

            console.log("onload");

            sock = new WebSocket(wsuri);

            sock.onopen = function() {
                console.log("connected to " + wsuri);
            }

            sock.onclose = function(e) {
                console.log("connection closed (" + e.code + ")");
            }

            sock.onmessage = function(e) {
                console.log("message received: " + e.data);
            }

            sock.onerror = function(e) {
                console.log("connected error: " + e.data);
            }
        };

        function send() {
            var msg = document.getElementById('message').value;
            sock.send(msg);
        };
    </script>
    <h1>WebSocket Echo Test</h1>
    <form>
        <p>
            Message:
            <input id="message" type="text" value="Hello, world!"></p>
    </form>
    <button onclick="send();">Send Message</button>
</body>
</html>